package ai.george.quickstart.controller;

import com.alibaba.cloud.ai.dashscope.chat.DashScopeChatOptions;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.ai.chat.messages.UserMessage;
import org.springframework.ai.chat.model.ChatModel;
import org.springframework.ai.chat.model.ChatResponse;
import org.springframework.ai.chat.prompt.Prompt;
import org.springframework.ai.content.Media;
import org.springframework.util.MimeTypeUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.net.URI;
import java.net.URISyntaxException;
import java.util.List;


@Tag(name = "Image示例")
@RestController
@RequestMapping("/image")
public class ImageController {




    private final ChatModel chatModel;


    public ImageController(ChatModel chatModel) {
        this.chatModel = chatModel;
    }



    @Operation(summary = "图片识别", description = "使用qwen3-vl-plus模型进行图片识别")
    @GetMapping("/image-recognition")
    public String imageRecognition() throws URISyntaxException {
        DashScopeChatOptions chatOptions = DashScopeChatOptions.builder()
                .withModel("qwen3-vl-plus")
                .withMultiModel(true) // qwen3-vl-plus的调用需要启用多模型
                .build();
        UserMessage userMessage = UserMessage.builder()
                .text("这个图片中的内容是什么")
                .media(new Media(MimeTypeUtils.IMAGE_JPEG, new URI("https://dashscope.oss-cn-beijing.aliyuncs.com/images/dog_and_girl.jpeg")))
                .build();
        Prompt prompt = new Prompt(List.of((userMessage)), chatOptions);
        ChatResponse call = chatModel.call(prompt);
        String result = call.getResult().getOutput().toString();
        return result;
    }


}
